{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9da89162",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:02:24.194622Z",
     "start_time": "2024-06-28T09:02:23.461571Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8f6a8e41",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:03:09.941897Z",
     "start_time": "2024-06-28T09:03:09.875782Z"
    }
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv('ERP_KHXD.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0226ddef",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:05:07.714160Z",
     "start_time": "2024-06-28T09:05:07.697644Z"
    }
   },
   "outputs": [],
   "source": [
    "customer_totals = df.groupby('khxx_id')['fhdw'].sum()  # 假设客户ID列名为'CustomerID'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "40ee71e3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:05:23.989246Z",
     "start_time": "2024-06-28T09:05:23.981011Z"
    }
   },
   "outputs": [],
   "source": [
    "max_customer_id = customer_totals.idxmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8e244482",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:09:18.813561Z",
     "start_time": "2024-06-28T09:09:18.800540Z"
    }
   },
   "outputs": [],
   "source": [
    "top100_customers = customer_totals.sort_values(ascending=False).head(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c9d5de65",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:09:31.682575Z",
     "start_time": "2024-06-28T09:09:31.673058Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "khxx_id\n",
      "497    199655.93\n",
      "86     130410.47\n",
      "378     82139.00\n",
      "461     76833.00\n",
      "152     57597.00\n",
      "         ...    \n",
      "567      5930.00\n",
      "398      5900.00\n",
      "216      5805.48\n",
      "314      5801.34\n",
      "486      5785.23\n",
      "Name: fhdw, Length: 100, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "print(top100_customers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "aa7ad33f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-06-28T09:10:37.404129Z",
     "start_time": "2024-06-28T09:10:37.380520Z"
    }
   },
   "outputs": [],
   "source": [
    "top100_customers.to_csv('需求量前一百的客户')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b4583a5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
